/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Agregar_Item.java
 *
 * Created on 25-feb-2011, 9:43:31
 */

package puntoventa;

import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author gadiaz3
 */
public class Agregar_Item extends javax.swing.JFrame {

    /** Creates new form Agregar_Item */
    public Agregar_Item() {
        initComponents();
        this.setLocationRelativeTo(this);
       }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        FID = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        FNom = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        FStock = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        FProv = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        CancelarB = new javax.swing.JButton();
        AddProdB = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        FPrecio = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Agregar Nuevo Producto");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        jLabel1.setText("Nuevo Producto");

        jLabel2.setText("ID:");

        jLabel3.setText("Nombre del Producto:");

        jLabel4.setText("Cantidad de Stock:");

        jLabel5.setText("Precio:");

        CancelarB.setText("Volver");
        CancelarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarBActionPerformed(evt);
            }
        });

        AddProdB.setText("Crear nuevo Producto...");
        AddProdB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddProdBActionPerformed(evt);
            }
        });

        jLabel6.setText("Proveedor:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(224, Short.MAX_VALUE)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(20, 20, 20)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel2)
                                    .add(jLabel3)
                                    .add(jLabel4)
                                    .add(jLabel6)
                                    .add(jLabel5)))
                            .add(layout.createSequentialGroup()
                                .add(41, 41, 41)
                                .add(CancelarB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(AddProdB, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                            .add(FID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, FNom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                            .add(FProv, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                            .add(FStock, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                            .add(FPrecio, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(FNom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FStock, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .add(8, 8, 8)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FProv, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FPrecio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5))
                .add(39, 39, 39)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(AddProdB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(CancelarB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AddProdBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddProdBActionPerformed
        String ID = FID.getText();
        String Nombre = FNom.getText();
        String Stock = FStock.getText();
        String Prov = FProv.getText();
        String Precio = FPrecio.getText();

            //Conexión a la BD
        try {

            Connection c = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/PDV", "root","");
            Statement sql = (Statement) c.createStatement();


            sql.executeUpdate("insert into Productos(ID,Nombre,Stock,Proveedor,Precio) values(" + ID + ",'" + Nombre + "'," + Stock + ",'" + Prov + "'," + Precio +")");

            JOptionPane.showMessageDialog(null, "Producto [" + ID + "] " + Nombre + ", agregado!.", "Atencion", JOptionPane.INFORMATION_MESSAGE);

            FID.setText("");
            FNom.setText("");
            FStock.setText("");
            FProv.setText("");
            FPrecio.setText("");

        } catch (SQLException ex) {

            ex.printStackTrace();
        }
    }//GEN-LAST:event_AddProdBActionPerformed

    private void CancelarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarBActionPerformed
        Administrador Admin = new Administrador();
        Admin.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_CancelarBActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Agregar_Item().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddProdB;
    private javax.swing.JButton CancelarB;
    private javax.swing.JTextField FID;
    private javax.swing.JTextField FNom;
    private javax.swing.JTextField FPrecio;
    private javax.swing.JTextField FProv;
    private javax.swing.JTextField FStock;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables

}
